﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Data.EntityClient;
using System.Runtime.Serialization;

namespace CustomerService
{
    public partial class SalesManagerEntities : ObjectContext
    {
        private codeState[] _cachedStates = null;
        private codeCountry[] _cachedCountries = null;
        private codeLanguage[] _cachedLanguages = null;

        public codeState[] CachedStates
        {
            get
            {
                if (_cachedStates == null)
                    _cachedStates = (from c in codeState
                                     select c).ToArray();
                return _cachedStates;
            }
        }

        public codeCountry[] CachedCountries
        {
            get
            {
                if (_cachedCountries == null)
                    _cachedCountries = (from c in codeCountry
                                     select c).ToArray();
                return _cachedCountries;
            }
        }

        public codeLanguage[] CachedLanguages
        {
            get
            {
                if (_cachedLanguages == null)
                    _cachedLanguages = (from c in codeLanguage
                                        select c).ToArray();
                return _cachedLanguages;
            }
        }
    }

    public partial class tblPerson : global::System.Data.Objects.DataClasses.EntityObject
    {
        public tblPerson()
        {
            FirstName = string.Empty;
            LastName = string.Empty;
            LanguageReference = new System.Data.Objects.DataClasses.EntityReference<codeLanguage>() { EntityKey = new System.Data.EntityKey("SalesManagerEntities.codeLanguage", "LanguageID", 1) };
        }
    }

    public partial class tblAddress : global::System.Data.Objects.DataClasses.EntityObject
    {
        public tblAddress()
        {
            Address1 = string.Empty;
            CountryReference = new System.Data.Objects.DataClasses.EntityReference<codeCountry>() { EntityKey = new System.Data.EntityKey("SalesManagerEntities.codeCountry", "CountryID", 468) };
        }
    }

    public partial class tblCustomer : global::System.Data.Objects.DataClasses.EntityObject
    {
        public tblOrderHeader[] cachedOrderHeaders;
        public tblOrderDetail[] cachedOrderDetails;
        public tblContactPoint[] cachedContactPoints;
        public tblSequenceOrder[] cachedSequenceOrders;
        public tblSequenceStep[] cachedSequenceSteps;
        public tblRefund[] cachedRefunds;
        public tblRMAReturn[] cachedRMAReturns;
        public tblReturnDetail[] cachedReturnDetails;
        public tblTransaction[] cachedTransactions;
        public tblMiscDef[] cachedMiscDefs;
    }

    public partial class tblOrderHeader : global::System.Data.Objects.DataClasses.EntityObject
    {
        public tblOrderHeader()
        {
            OrderDate = DateTime.Today;
            ProjShipDate = DateTime.Today;
            ImportDate = DateTime.Today;
            ProductTotal = 0;
            Shipping = 0;
            Taxes = 0;
            OrderTotal = 0;
        }

        public string OrderListInfo
        {
            get
            {
                string ret =
                    OrderDate.ToShortDateString() + "<br />" +
                    OrderStatus.Name;
                // Put the first shipment date into the list info
                //if (OrderStatus.OrderStatusCode == "S" || OrderStatus.OrderStatusCode == "R")
                //    ret += "<br />" + ((DateTime)OrderShipments.OrderBy(o => o.Shipment.ShippedDate).First().Shipment.ShippedDate).ToShortDateString();

                return ret;
            }
        }

        public bool CanEdit
        {
            get { return (OrderStatus.OrderStatusCode == "P"); }
        }

        public bool CanCancel
        {
            get { return (OrderStatus.OrderStatusCode == "P"); }
        }

        public bool CanRefund
        {
            get { return true; }
        }
    }

    public partial class tblOrderDetail : global::System.Data.Objects.DataClasses.EntityObject
    {
        public decimal TotalPrice
        {
            get { return Convert.ToDecimal(Qty * (Convert.ToDouble(UnitPrice) * (1 - Discount))); }
        }
    }

    public partial class tblRefund : global::System.Data.Objects.DataClasses.EntityObject
    {
        public string LineDescription
        {
            get
            {
                if (OrderDetailID != null)
                    return OrderDetail.Product.ShortName;
                if (OrderTaxID != null)
                    return OrderTax.TaxRate.Name;
                return "Shipping";
            }
        }
    }

    public partial class tblTransactionDetail : global::System.Data.Objects.DataClasses.EntityObject
    {
        public decimal Debit
        {
            get { return (TransactionDetailTypeCode == "D") ? Amount : 0; }
        }

        public decimal Credit
        {
            get { return (TransactionDetailTypeCode == "C") ? Amount : 0; }
        }
    }

    public partial class tblAccount : global::System.Data.Objects.DataClasses.EntityObject
    {
        public string DisplayName
        {
            get
            {
                if (Name != null)
                    return Name;
                if (CardNumber != null)
                    return CardNumber.ToString();
                return BankAccountNumber + " " + BankRoutingNumber;
            }
        }
    }

    public class CustomerSearch : global::System.Data.Objects.DataClasses.EntityObject
    {
        [EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = true)]
        [DataMemberAttribute()]
        public string SearchKeyType { get; set; }
        [EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = false)]
        [DataMemberAttribute()]
        public Int32 CustomerID { get; set; }
        [EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = true)]
        [DataMemberAttribute()]
        public string Name { get; set; }
        [EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = true)]
        [DataMemberAttribute()]
        public string Address1 { get; set; }
        [EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = true)]
        [DataMemberAttribute()]
        public string City { get; set; }
        [EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = true)]
        [DataMemberAttribute()]
        public string State { get; set; }
        [EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = true)]
        [DataMemberAttribute()]
        public string PostalCode { get; set; }
        [EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = true)]
        [DataMemberAttribute()]
        public DateTime? OrderDate { get; set; }
    }
}
